import java.util.Scanner;

/**
 * @author gao
 * @date 2025/7/6 12:05
 */

class ListNode {
    int val;
    ListNode next;

    public ListNode() {
    }

    public ListNode(int val) {
        this.val = val;
    }

    public ListNode(int val, ListNode next) {
        this.val = val;
        this.next = next;
    }
}

public class Solution {
    public ListNode mergeKLists(ListNode[] lists) {
        return merge(lists, 0, lists.length - 1);
    }

    private ListNode merge(ListNode[] lists, int left, int right) {
        if (left > right) {
            return null;
        }
        if (left == right) {
            return lists[left];
        }
        // 计算中间位置
        int mid = (left + right) / 2;
        // 递归合并左半部分链表
        ListNode l1 = merge(lists, left, mid);
        // 递归合并右半部分链表
        ListNode l2 = merge(lists, mid + 1, right);

        return mergeTwoList(l1, l2);
    }

    private ListNode mergeTwoList(ListNode l1, ListNode l2) {
        // 如果l1为空，则返回l2
        if (l1 == null) {
            return l2;
        }
        // 如果l2为空，则返回l1
        if (l2 == null) {
            return l1;
        }
        ListNode head = new ListNode(0);
        ListNode cur1 = l1, cur2 = l2, prev = head;
        // 循环遍历l1和l2，直到其中一个链表为空
        while (cur1 != null && cur2 != null) {
            // 如果l1的节点值小于等于l2的节点值，则将l1的节点连接到新链表的尾部
            if (cur1.val <= cur2.val) {
                prev.next = cur1;
                prev = cur1;
                cur1 = cur1.next;
                // 否则，将l2的节点连接到新链表的尾部
            } else {
                prev.next = cur2;
                prev = cur2;
                cur2 = cur2.next;
            }
        }
        // 如果l1不为空，则将l1的剩余节点连接到新链表的尾部
        if (cur1 != null) {
            prev.next = cur1;
            // 否则，将l2的剩余节点连接到新链表的尾部
        } else {
            prev.next = cur2;
        }
        return head.next;
    }

    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        while (in.hasNext()) {
            int k = in.nextInt();
            ListNode[] lists = new ListNode[k];
            for (int i = 0; i < k; i++) {
                int n = in.nextInt();
                lists[i] = BuildList(n, in);
            }
            Solution solution = new Solution();
            Print(solution.mergeKLists(lists));
        }
    }

    private static void Print(ListNode head) {
        ListNode cur = head;
        while (cur != null) {
            System.out.print(cur.val + " ");
            cur = cur.next;
        }
    }

    private static ListNode BuildList(int n, Scanner in) {
        ListNode head = null;
        ListNode tail = null;

        for (int i = 0; i < n; i++) {
            int val = in.nextInt();
            ListNode newNode = new ListNode(val);
            if (head == null) {
                head = newNode;
                tail = newNode;
            } else {
                tail.next = newNode;
                tail = newNode;
            }
        }
        return head;
    }
}